// 获取绝对值
function getAbs(num){
    num= Number(num);
    return Number(num)<0 ? -num:num;
}

function getAbs2(num){
    return Math.abs(num)
}
const arr=[-1,0,1];

//console.log(getAbs(-1));
//console.log(getAbs2(-1));


//计算百分比
function calcPercentage(num1=0,num2=0){
    let percentage=0;
    let rs=num1/num2;
    //0.直接算
    //问题：有除不尽的会都显示
    console.log("0",rs*100);
    //1.直接切割，取前小数前4位：先把4位小数变成整数，然后再除以100
    //问题：如果整除则无法显示小数点
    percentage=Math.round(rs*100)/100*100;
    console.log("1",percentage);

    //2.保留小数点,toFixed四舍五入
    percentage=(rs*100).toFixed(2);
    console.log("2",percentage);

    //3.

    return percentage;

}

calcPercentage(1,4);